import { permission_doctor_bind_platform } from '@/services/platformuser';
import { ActionType, ProForm, ProFormTextArea } from '@ant-design/pro-components';
import { Divider, message, Modal } from 'antd';
interface Iprops {
  isShowRefuseModal: (show: boolean) => void;
  isRefuseModalOpen: boolean;
  id: number | undefined;
  actionRef2: React.MutableRefObject<ActionType | undefined>;
}
const Refuse = (props: Iprops) => {
  const { isRefuseModalOpen, isShowRefuseModal, actionRef2, id } = props;

  // 确认拒绝
  const refuse = async (value: { refuse_reason: string }) => {
    let request_body = {
      id,
      status: 2,
      refuse_reason: value.refuse_reason,
    };
    let res: any = await permission_doctor_bind_platform(request_body);
    console.log(res);
    if (res.msg == 'ok') {
      message.success('审批拒绝成功');
      isShowRefuseModal(false);
      actionRef2.current?.reload();
    } else {
      message.error(res.msg);
    }
  };
  return (
    <Modal
      title="拒绝绑定"
      centered
      open={isRefuseModalOpen}
      onCancel={() => isShowRefuseModal(false)}
      destroyOnClose={true}
      width={500}
      footer={null}
    >
      <Divider />
      <ProForm
        onReset={() => isShowRefuseModal(false)}
        onFinish={(values: { refuse_reason: string }) => refuse(values)}
        submitter={{
          // 配置按钮文本
          searchConfig: {
            resetText: '取消',
            submitText: '确定',
          },
          resetButtonProps: {
            style: {
              display: 'block',
              position: 'absolute',
              left: 'calc(50% - 107px)',
            },
          },
          submitButtonProps: {
            style: {
              display: 'block',
              position: 'absolute',
              right: 'calc(50% - 107px)',
            },
          },
        }}
      >
        <ProFormTextArea
          name="refuse_reason"
          label="拒绝原因"
          placeholder="请填写拒绝原因"
          rules={[
            { required: true, message: '请填写拒绝绑定原因' },
            { max: 100, message: '字数限制最大为100个字符！' },
            { pattern: /(^\S)((.)*\S)?(\S*$)/, message: '不能输入空格' },
          ]}
        />
        <br />
      </ProForm>
      <br />
    </Modal>
  );
};
export default Refuse;
